<?php
class AjaxUserInformer_Bootstrap extends Engine_Application_Bootstrap_Abstract {
	
	public function __construct($application) {
		parent::__construct ( $application );
		
		if (! Engine_Api::_ ()->hasModuleBootstrap ( 'MsepCore' )) {
			$moduleInflected = Engine_Api::inflect ( 'msep-core' );
			$moduleDir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleInflected;
			
			$bootstrapClass = $moduleInflected . '_Bootstrap';
			$bootstrapPath = $moduleDir . '/Bootstrap.php';
			
			if (file_exists ( $bootstrapPath )) {
				include_once $bootstrapPath;
				
				$moduleBootstrap = new $bootstrapClass ( $application );
				$moduleBootstrap->bootstrap ();
				
				Engine_Api::_ ()->setModuleBootstrap ( $moduleBootstrap );
			} else {
				throw new Engine_Application_Bootstrap_Exception ( 'Install MSEP Core!' );
			}
		}
	}
	
	public function _initHeadScript() {
		$settings = Engine_Api::_ ()->getApi ( 'settings', 'MsepCore' );
		
		$this->getContainer ()->get ( 'Zend_View' )->headScript ()->appendFile ( 'application/modules/AjaxUserInformer/externals/scripts/core.js', 'text/javascript' );
		
		Zend_Registry::set ( 'AjaxUserInformer_Init', "
                  window.addEvent('domready', function()
                  {
                        msep.ajaxui.init(
                        {
                              'tl': {$settings->ajaxui->corner_tl_radius},
                              'tr': {$settings->ajaxui->corner_tr_radius},
                              'bl': {$settings->ajaxui->corner_bl_radius},
                              'br': {$settings->ajaxui->corner_br_radius},
                              'border': {$settings->ajaxui->border_width},
                              'border-color': '{$settings->ajaxui->border_color}',
                              'background-color': '{$settings->ajaxui->background_color}',
                              'mouseover': {$settings->ajaxui->mouse_over}
                        });

                        msep.ajaxui.getUsers();
                  });
            " );
		
		$this->initActionHelperPath ();
		
		Zend_Controller_Action_HelperBroker::addHelper ( new AjaxUserInformer_Controller_Action_Helper_Initialize () );
	}

}